package com.uphone.kingmall.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.uphone.kingmall.adapter.YongJinRankingAdapter;
import com.uphone.kingmall.base.BaseBean;
import com.uphone.kingmall.base.BaseListFragment;
import com.uphone.kingmall.bean.YongJinRankingBean;
import com.uphone.kingmall.listener.onNormalRequestListener;
import com.uphone.kingmall.utils.GsonUtils;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.OkGoUtils;

import java.util.ArrayList;

/**
 * author : SuMeng
 * e-mail : 986335838@qq.com
 * time   : 2019/05/22
 * desc   : xxxx 描述
 */
public class YongJinRankingFragment extends BaseListFragment {

    private int type;

    public static YongJinRankingFragment newInstance(int type) {

        Bundle args = new Bundle();

        YongJinRankingFragment fragment = new YongJinRankingFragment();
        fragment.type = type;
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected HttpParams getParams() {
        HttpParams params = new HttpParams();
        params.put("type", type);
        return params;
    }

    @Override
    protected String getUrl() {
        return MyUrl.sumUpRanking;
    }

    @Override
    protected void itemClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new YongJinRankingAdapter();
    }

    @Override
    public void initView(View view) {
        ll.setBackgroundColor(Color.WHITE);
    }

    @Override
    protected void loadData(int page) {
        this.page = page;
        String url = getUrl();
        if (TextUtils.isEmpty(url)) {
            return;
        }
        OkGoUtils.normalRequest(url, getParams(), new onNormalRequestListener() {
            @Override
            public void onSuccess(String body, int code) {
                if (code == 0) {
                    YongJinRankingBean bean = GsonUtils.getGson().fromJson(body, YongJinRankingBean.class);
                    if (bean != null && bean.getMap() != null) {
                        dataList = bean.getMap().getRecordResumeVos();
                        YongJinRankingBean.MapBean.RecordResumeVoBean recordResumeVo = bean.getMap().getRecordResumeVo();
                        if (dataList == null)
                            dataList = new ArrayList();
                        dataList.add(0, recordResumeVo);
                    }
                    mAdapter.setNewData(dataList);
                    if (dataList == null || dataList.size() == 0 || dataList.size() == 1) {
                        tvEmpty.setVisibility(View.VISIBLE);
                    } else {
                        tvEmpty.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onError(Response<String> response) {

            }
        });
    }

    @Override
    protected BaseBean getBeans() {
        return null;
    }
}
